import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/helloworld',
    name :'HellowWorld',
    component: ()=>import('../components/HelloWorld.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: ()=>import('../views/LoginView.vue')
  },
  {
    path: '/register',
    name: 'RegisterView',
    component: () => import('../views/RegisterView.vue')
  },
  {
    path: '/',
    redirect:{path: '/vedioIndex'}
  },
  {
    path: '/vedioIndex',
    redirect:{name:'AllLine'},
    component: () => import('../views/Index.vue'),
    children:[
      {
        path: 'allline',
        name: 'AllLine',
        component: ()=> import('../views/vedioCheck/Line/AllLine.vue')
      },
      {
        path: 'alldevices',
        name: 'AllDevices',
        component:()=>import('../views/vedioCheck/Line/AllDevices.vue')
      },
      {
        path: 'devicedetail',
        name: 'DeviceDetail',
        component: ()=>import('../views/vedioCheck/device/DeviceDetail.vue')
      },
      {
        path: 'generate',
        name: 'GenerateTask',
        component: ()=> import('../views/vedioCheck/device/GenerateTask.vue')
      }
    ]
  },
  {
    path: '/graphic',
    redirect: {name: 'GraphicIndex'},
    component:()=> import('../views/Index.vue'),        //底部导航栏
    children:[
      {
        path: 'index',
        name: 'GraphicIndex',
        component: () => import('../views/graphicCheck/IndexView.vue')      //顶部导航栏+所偶有设备缩略图
      },
      {
        path: 'selectCharts',
        name:'selectCharts',
        component: ()=> import('../views/graphicCheck/AllCharts.vue'),      //顶部导航栏带返回按钮
        children:[
          {
            path: 'miniCharts',
            name: 'MiniCharts',
            component: () => import('../views/graphicCheck/ChartView/miniCharts.vue')   //所有图标的mini图
          },
          {
            path: 'temprature',
            name: 'Temprature',
            component :()=> import('../views/graphicCheck/ChartView/Temprature.vue')
          },
          {
            path: 'virbation',
            name: 'Virbation',
            component: ()=> import('../views/graphicCheck/ChartView/Virbation.vue')
          },
          {
            path: 'speed',
            name: 'Speed',
            component: ()=> import('../views/graphicCheck/ChartView/Speed.vue')
          },
          {
            path: 'noise',
            name: 'Noise',
            component: ()=> import('../views/graphicCheck/ChartView/Noise.vue')
          }
        ]
      },
      {
        path:'check_process',
        name:'CheckProcess',
        component:()=>import('../views/graphicCheck/ProcessView.vue')
      }
    ]
  },
  {
    path: '/tasks',
    redirect: {name: 'TaskIndex'},
    component:()=> import('../views/Index.vue'),
    children:[
      {
        path: 'index',
        name: 'TaskIndex',
        component: ()=> import('../views/TaskPage/IndexView.vue'),
        children:[
          {
            path:'alltasks',
            name:'AllTasks',
            component:()=> import('../views/TaskPage/Tasks/AllTasks.vue')
          },
          {
            path:'finishedtasks',
            name:'FinishedTasks',
            component:()=> import('../views/TaskPage/Tasks/FinishedTasks.vue')
          },
          {
            path:'doingtasks',
            name:'DoingTasks',
            component:()=> import('../views/TaskPage/Tasks/DoingTasks.vue')
          },
          {
            path:'waitingtasks',
            name:'WaitingTasks',
            component:()=> import('../views/TaskPage/Tasks/WaitingTasks.vue')
          },
          {
            path:'minetasks',
            name:'MineTasks',
            component:()=> import('../views/TaskPage/Tasks/MineTasks.vue')
          }
        ]
      }
    ]

  },
  {
    path:'/mine',
    redirect: {name:'MineIndex'},
    component: () => import('../views/Index.vue'),
    children:[
      {
        path:'index',
        name:'MineIndex',
        component:()=>import('../views/MinePage/IndexView.vue')
      },
      {
        path: 'sendMessage',
        name: 'SendMessage',
        component:()=> import('../views/MinePage/SendMessage.vue')
      }
    ]

  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to,from,next)=>{
  // console.log(sessionStorage.getItem('isLogin'),next.name)
  if(to.name === 'Login' || sessionStorage.getItem('isLogin') === 'true'){
    next()
  }
  else{
      next({name:'Login'})
  }


})

export default router
